<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

//File này sẽ được include ở file ulu/functions.php
//Quốc code các function trong này
//gọi ajax đúng theo dạng hook của worpress
//http://truongthanhtung.wordpress.com/2013/12/14/ajax-trong-wordpress/
//file template của trang quản lý sản phẩm admin nằm trong 
//file tpl-product-management.php
function get_data_product($page, $amount){
    global $wpdb;
    $product_data_array = $wpdb->get_results("SELECT * FROM ys_product LIMIT ".$amount." OFFSET ".($page-1)*$amount , OBJECT);
    $pageNum = $wpdb->get_var("SELECT COUNT(*) FROM ys_product");
    $product_data = array(
        "pageNum" => $pageNum,
        "data" => $product_data_array
    );
    return $product_data;
}

function get_product_link($id)
{
    $url=get_page_link(get_id_by_filename("tpl-product-single.php"))."&pid=".$id;
    return $url;
}
function get_edit_product_link($id)
{
    $url=get_page_link(get_id_by_filename("tpl-add-product.php"))."&product_id=".$id;
    return $url;
}


 
function delete_product() {
    global $wpdb;
    // Handle request then generate response using WP_Ajax_Response
    //$querystr = "DELETE FROM ys_product WHERE id =".$_POST["data"];
    $deleteid = $_POST["data"];
    echo $wpdb->delete( "ys_product", array('id' => $deleteid));
}
add_action( 'wp_ajax_delete_product', 'delete_product' );



?>
